<?php

class PermissionsTableSeeder extends Seeder {

    public function run()
    {

        $permissions = array();
        array_push($permissions, array(
            'name' => 'manage_staff',
            'display_name' => '管理员管理'
        ));
        array_push($permissions, array(
            'name' => 'view_staff',
            'display_name' => '查看管理员详情'
        ));
        array_push($permissions, array(
            'name' => 'create_staff',
            'display_name' => '创建管理员'
        ));
        array_push($permissions, array(
            'name' => 'update_staff',
            'display_name' => '修改管理员'
        ));
        array_push($permissions, array(
            'name' => 'delete_staff',
            'display_name' => '删除管理员'
        ));
        array_push($permissions, array(
            'name' => 'manage_role',
            'display_name' => '角色管理'
        ));
        array_push($permissions, array(
            'name' => 'create_role',
            'display_name' => '创建角色'
        ));
        array_push($permissions, array(
            'name' => 'show_role',
            'display_name' => '查看角色详情'
        ));
        array_push($permissions, array(
            'name' => 'update_role',
            'display_name' => '修改角色'
        ));
        array_push($permissions, array(
            'name' => 'delete_role',
            'display_name' => '删除角色'
        ));
        array_push($permissions, array(
            'name' => 'manage_food',
            'display_name' => '餐品管理'
        ));
        array_push($permissions, array(
            'name' => 'create_food',
            'display_name' => '创建餐品'
        ));
        array_push($permissions, array(
            'name' => 'show_food',
            'display_name' => '查看餐品详情'
        ));
        array_push($permissions, array(
            'name' => 'update_food',
            'display_name' => '修改餐品'
        ));
        array_push($permissions, array(
            'name' => 'delete_food',
            'display_name' => '删除餐品'
        ));
        array_push($permissions, array(
            'name' => 'manage_menu',
            'display_name' => '菜单管理'
        ));
        array_push($permissions, array(
            'name' => 'create_menu',
            'display_name' => '创建菜单'
        ));
        array_push($permissions, array(
            'name' => 'show_menu',
            'display_name' => '查看菜单详情'
        ));
        array_push($permissions, array(
            'name' => 'update_menu',
            'display_name' => '修改菜单'
        ));
        array_push($permissions, array(
            'name' => 'delete_menu',
            'display_name' => '删除菜单'
        ));
        array_push($permissions, array(
            'name' => 'manage_member',
            'display_name' => '会员管理'
        ));
        array_push($permissions, array(
            'name' => 'view_member',
            'display_name' => '查看会员详情'
        ));
        array_push($permissions, array(
            'name' => 'create_member',
            'display_name' => '创建会员'
        ));
        array_push($permissions, array(
            'name' => 'update_member',
            'display_name' => '修改会员'
        ));
        array_push($permissions, array(
            'name' => 'delete_member',
            'display_name' => '删除会员'
        ));
        array_push($permissions, array(
            'name' => 'manage_carousel',
            'display_name' => '餐品管理'
        ));
        array_push($permissions, array(
            'name' => 'create_carousel',
            'display_name' => '创建餐品'
        ));
        array_push($permissions, array(
            'name' => 'show_carousel',
            'display_name' => '查看餐品详情'
        ));
        array_push($permissions, array(
            'name' => 'update_carousel',
            'display_name' => '修改餐品'
        ));
        array_push($permissions, array(
            'name' => 'delete_carousel',
            'display_name' => '删除餐品'
        ));
        array_push($permissions, array(
            'name' => 'manage_order',
            'display_name' => '订单管理'
        ));
        array_push($permissions, array(
            'name' => 'show_order',
            'display_name' => '查看订单详情'
        ));
        array_push($permissions, array(
                'name' => 'manage_setting',
                'display_name' => '系统设定'
        ));

        DB::table('permissions')->insert( $permissions );


        $role_id_admin = Role::where('name', '=', 'administrators')->first()->id;
        $permission_role = array();
        for($i=1;$i<=count($permissions);$i++){
            $a = array(
                'role_id'       => $role_id_admin,
                'permission_id' => $i
            );
            array_push($permission_role,$a);
        }

        DB::table('permission_role')->insert( $permission_role );

    }

}